CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
OBJS = $(TARGET)_generated.o embc_mod_wrapper.o
MDIR = rtai
RTAIDIR = /usr/realtime
COMEDIDIR = /usr/src/comedi
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)
EXTRA_CFLAGS += -DEXPORT_SYMTAB $(shell $(RTAIDIR)/bin/rtai-config --module-cflags)  -I$(EXTRA_INCL) -I$(COMEDIDIR)/include -DRTAI
MACH = $(shell uname -m)

ifeq ($(MACH), x86_64)
# workaround for kernel build system sometimes addind -mno-see and -mno-sse2 which messes up our
# use of floats in the kernel
EXTRA_CFLAGS += -msse -msse2
endif

ifeq ($(KERNELRELEASE),) 

all: 
ifdef COMPILER_OVERRIDE
		make -C '$(KDIR)' M='$(PWD)' COMPILER_OVERRIDE='$(COMPILER_OVERRIDE)' modules
else
		make -C '$(KDIR)' M='$(PWD)' modules
endif

install:
	su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"

clean:
	-rm -f *.o *.ko .*.cmd .*.flags *.mod.c *~
	make -C $(KDIR) M=$(PWD) clean

else	

# override the CC defined by kernel makefiles to come from our COMPILER_OVERRIDE option
ifdef COMPILER_OVERRIDE
  CC = $(COMPILER_OVERRIDE)
endif

obj-m      := $(TARGET).o

$(TARGET)-objs := $(OBJS)

-include $(KDIR)/Rules.make

endif
